package com.burgeon.backend.SHOPBACKEND.controller;

import com.burgeon.backend.SHOPBACKEND.entity.Brand;
import com.burgeon.backend.SHOPBACKEND.entity.Classify;
import com.burgeon.backend.SHOPBACKEND.service.GoodsClassifyService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("shopbackent/classify")
public class GoodsClassifyController extends BaseController {
    @Autowired
    private GoodsClassifyService goodsClassifyService;

    //品牌排序置顶
    @RequestMapping("upBrandTop")
    public ResponseResult<Void> upBrandTop(String id, String account) {
        goodsClassifyService.upBrandTop(id, account);
        return new ResponseResult<Void>(SUCCESS);
    }

    @RequestMapping("upBrandNub")
    public ResponseResult<Void> upBrandNub(String id, Integer nub, String account) {
        goodsClassifyService.upBrandNub(id, nub, account);
        return new ResponseResult<Void>(SUCCESS);
    }

    @RequestMapping("upBrand")
    public ResponseResult<Void> upBrandShow(String id, String isShow) {
        goodsClassifyService.upBrandShow(id, isShow);
        return new ResponseResult<Void>(SUCCESS);
    }

    @RequestMapping("getBrand")
    public ResponseResult<List<Brand>> getBrand(String account) {
        List<Brand> data = goodsClassifyService.getBrand(account);
        return new ResponseResult<List<Brand>>(SUCCESS, data);
    }

    /**
     * 修改是否展示状态
     *
     * @param isShow
     * @param id
     * @return
     */
    @RequestMapping("upIsShow")
    public ResponseResult<Void> updateIsShowById(String isShow, String id) {
        goodsClassifyService.updateIsShowById(isShow, id);
        return new ResponseResult<Void>(SUCCESS);
    }

    @RequestMapping("show")
    public ResponseResult<List<Classify>> getClassify(String account) {
        List<Classify> data = goodsClassifyService.showClassify(account);
        return new ResponseResult<List<Classify>>(SUCCESS, data);
    }

    /**
     * 添加商品类型
     *
     * @param classify
     * @return
     */
    @RequestMapping("insert")
    public ResponseResult<Void> insertClassify(Classify classify, String account) {

        classify.setToken(account);
        classify.setAccount(account);
        goodsClassifyService.insertClassify(classify);
        return new ResponseResult<Void>(SUCCESS);
    }

    /**
     * 根据ID删除商品类型
     *
     * @param id
     * @return
     */
    @RequestMapping("delete")
    public ResponseResult<Void> deleteClassify(Integer id) {
        goodsClassifyService.deleteClassify(id);
        return new ResponseResult<Void>(SUCCESS);
    }

    /**
     * 根据ID修改商品类型
     *
     * @param classify
     * @return
     */
    @RequestMapping("update")
    public ResponseResult<Void> updateClassifyById(Classify classify, String account) {

        goodsClassifyService.updateClassifyById(classify);
        return new ResponseResult<Void>(SUCCESS);
    }

}